<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
			String data = request.getParameter("data");
%>
<!DOCTYPE html>

<head>
<meta charset="utf-8" />
<base href="<%=basePath%>">
<title>青岛力神动力电池远程监控平台</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="" name="description" />
<meta content="" name="author" />
<style>
	#_loginSeizeWarning p{
		font-size: 16px;
		color: #666;
		font-family: 宋体;
		font-weight: bold;
	}
	
	#_accountExpiredWarning p{
		font-size: 16px;
		color: #666;
		font-family: 宋体;
		font-weight: bold;
	}
	.message-box{display: none; width: 460px; padding: 0 19px; position: fixed; top: 41px; left: 205px; border: 1px solid #ddd; border-top-width: 0; background-color: #FFF; color: #333; font-size: 14px;z-index: 999999;}
	.message-box *{margin: 0; padding: 0;}
	.message-box a{text-decoration: none;}
	.message-box ul{ list-style: none;}
	.message-box li{display: flex; height: 60px; align-items: center; border-bottom: 1px solid #ddd;}
	.message-box li a{display: inline-block; width: 400px; overflow: hidden; color: #333; white-space: nowrap; text-overflow: ellipsis;}
	.message-box li a:hover{color: #35aa47; text-decoration: none;}
	.message-box li time{display: block; width: 90px; text-align: right; color: #999;}

	.more-msg{display: block; line-height: 60px; color: #35aa47;}
	.more-msg:hover{color: #35aa47;text-decoration: none;}
	.msg-btn{width: 45px; height: 40px; margin: 0 auto; position: relative; z-index: 999999;background: url("media/rms-images/message-news.png") center no-repeat;background-size: 23px auto; cursor: pointer;}
	.msg-btn > span{position: absolute; bottom: 2px; right: 2px;  padding: 0 6px; text-align: center; font-size: 12px; border-radius: 99px !important; -webkit-border-radius: 99px !important; background: #ff2115; color: #FFF;}
</style>
<jsp:include page="/pages/common/hd_common.jsp"></jsp:include>
</head>
<body class="page-header-fixed page-footer-fixed">
	<div class="page-container">
		<jsp:include page="/pages/common/fr_head.jsp"></jsp:include>
		<jsp:include page="/pages/common/fr_content.jsp"></jsp:include>
		<!-- confirm 和  alert窗口 -->
		<jsp:include page="/pages/common/fr_footer.jsp"></jsp:include>
	</div>
	<jsp:include page="/pages/common/ft_common.jsp"></jsp:include>
	
	<!-- <div id="notify" class="message-box">
	
	<ul id="messageList">
	</ul>
	
	<a class="more-msg" id="findAllMessage" href='javascript:;' onclick='util.showContent("pages/message/sysMessage.jsp")'>查看所有消息&gt;&gt;</a>
	</div> -->
	
	<div id="_loginSeizeWarning" class="modal hide fade" tabindex="-1" data-backdrop="two-confirmation" data-keyboard="false">
		<div class="modal-body">
			<p>账号已在其他地方登陆，请重新登录！</p>
		</div>
		<div class="modal-footer">
			<button type="button" data-dismiss="modal" class="btn green">确定</button>
		</div>
	</div>
	
	<div id="_accountExpiredWarning" class="modal hide fade" tabindex="-1" data-backdrop="two-confirmation" data-keyboard="false">
		<div class="modal-body">
			<p>账户过期，请联系管理员！</p>
		</div>
		<div class="modal-footer">
			<button type="button" data-dismiss="modal" class="btn green">确定</button>
		</div>
	</div>
	<script type="text/javascript">
	//监控 刷新
	//定义一个全局定时器
	var monitorRefreshTimer;
	var monitorDetailCount = 1;
	//监控台
	var monitorConsoleRefreshTimer;
	var monitorConsoleDetailCount = 1;
	//客户监控台
	var cusmonitorConsoleRefreshTimer;
	var cusmonitorConsoleDetailCount = 1;
	//概览
	var overviewRefreshTimer;
	var overviewRefreshCount = 1;
	//自定义报警定时器
	var alertQueryRefreshTimer;
	var alertQueryRefreshCount = 1;
	//概览页面时钟
	var overviewColckRefreshTimer;
	var overviewColckRefreshCount = 1;
	
	//看板页面定时器
	var board1RefreshCount = 1;
	var board2RefreshCount = 1;
	var board3RefreshCount = 1;
	var board4RefreshCount = 1;
	
	var board1RefreshTimer;
	var board2RefreshTimer;
	var board3RefreshTimer;
	var board4RefreshTimer;
	
	
	var loginName;
	var displayName;
	var showMessage;
	var showMsgReceiveManage;
	
	
	
	var btnResource = {};
	    //ajax全局设置 session超时设置
		$.ajaxSetup({
			contentType : "application/x-www-form-urlencoded;charset=utf-8",
			complete : function(XMLHttpRequest, textStatus) {
				//通过XMLHttpRequest取得响应头，sessionstatus，  
				var sessionstatus = XMLHttpRequest
						.getResponseHeader("sessionstatus");
				if (sessionstatus == "timeout") {
					//如果超时就处理 ，指定要跳转的页面  
					window.location.href = 'login.jsp';
				}
			}
		});

		function createMenu(data) {
			var html = "";
			for ( var i = 0; i < data.length; i++) {
				var o = data[i];
				if (o['isLevel'] == "0") {
					html += "<li class=''><a href='javascript:;'> <i class='"+o['iconClass']+"'></i>";
					html += "<span class='title'>" + o['text']
							+ "</span><span class='arrow'></span></a>";
					html += "<ul class='sub-menu'>" + createMenu(o['childs']);
					html += "</ul></li>";
				} else {
					if (o['active'] == "1") {
						if (o['isSubMenu'] == "0") {
							html += "<li class='active'><a href='javascript:;' onclick='util.showContent(\""
									+ o['href']
									+ "\")'>  <i class='icon-home'></i>";
							html += "<span class='title' >" + o['text']
									+ "</span></a></li>";
						} else {
							html += "<li class='active'><a href='javascript:;' onclick='util.showContent(\""
									+ o['href'] + "\")'> ";
							html += o['text'] + " </a></li>";
						}
					} else {
						if (o['isSubMenu'] == "0") {
							html += "<li class=''><a href='javascript:;' onclick='util.showContent(\""
									+ o['href']
									+ "\")'>  <i class='icon-home'></i>";
							html += "<span class='title' >" + o['text']
									+ "</span></a></li>";
						} else {
							html += "<li class=''><a href='javascript:;' onclick='util.showContent(\""
									+ o['href'] + "\")'> ";
							html += o['text'] + " </a></li>";
							btnResource[o['href']] = o['buttons'];
						}
					}

				}
			}
			return html;
		};

		function getMessageNotification() {
			$("#messageList").empty();
			$.ajax({
				type:'get',
				async: true,
				url: 'main/message/getMessageNotification.mvc',
				dataType: "json",
				success:function(data){
					if(data && data.messageList.length>0) {
						$(".msg-btn span").show();
						var messageList = data.messageList;
						var html = ""
						$(".msg-btn span").text(data.count);
						for ( var i = 0; i < messageList.length; i++) {
							html += "<li>" +
										"<a href=\"javascript:;\" title=\""+messageList[i].messageContent+"\" onclick='util.showContent(\"pages/message/sysMessage.jsp\")'>" +
											messageList[i].messageContent +
										"</a> "+
										"<time>" + 
											messageList[i].pushDate +
										"</time> " +
									"</li>"

						}
						$("#messageList").append(html);
					} else {
						$(".msg-btn span").hide();
						var html = "<li class=\"no-message\">暂无未读消息提醒</li>";
						$("#messageList").append(html);
					}
				}
			});
		}
		
		jQuery(document).ready(function() {
			App.init();
			Index.init();
			getMessageNotification();
			var jsonStr = '${data}';
			loginName = '${loginName}';
			showMessage = '${showMessage}';
            showMsgReceiveManage = '${msgReceiveManage}';
			displayName = '${displayName}';
			homePageUrl = '${homePage}';
			/*if(showMessage == '1') {
			    $(".showMessage").show();
			} else {
			    $(".showMessage").hide();
			}*/
            if(showMsgReceiveManage === '1') {
                $("#msg_receive_manage").show();
            } else {
                $("#msg_receive_manage").hide();
            }
			$("#loginName").text(displayName + " ");
			var html = createMenu(eval('(' + jsonStr + ')'));
			$("#page-sidebar-menu").append(html);
			util.showContent(homePageUrl, null);
			//禁止backspace键返回上一页
			document.getElementsByTagName("body")[0].onkeydown = function (){
				if(event.keyCode==8){
					var elem = event.srcElement || event.currentTarget;
					var name = elem.nodeName;
					if(name=='BODY'){    
	                    return false;
	                }
				}
			};

			$('.msg-btn').hover(function() {
				/*console.log($('.msg-btn').css('z-index'));
				console.log($('.message-box').css('z-index'));*/
				var offset = $(".msg-btn").offset();
				var width = $(".message-box").width();
				//getMessageNotification();
				$(".message-box").css({
					left: offset.left - width+9  +"px"
				});
				$('.message-box').show();
			},function() {

				$('.message-box').hide();
			})
			
			$("#findAllMessage").on('click',  function(event) {
				event.preventDefault();
				/* Act on the event */
			});
			//退出登录
			$('#logOut').click(function(){
				 $.ajax({
				  type:'GET',
				  async: false,
				  url: 'main/loginOut.mvc',
				  dataType: "json",
				  success:function(data){
				 		 window.location.href='login.jsp';
				  }
				});
			});
			
			/* window.setInterval(function() {
				$.ajax({
				  type:'get',
				  async: false,
				  url: 'main/checkLoginStatus.mvc',
				  dataType: "json",
				  success:function(data){
				  	if (!data || data.msg == 'loginSeize') {
				  		$("#_loginSeizeWarning").modal("show");
				  	}else if(data.msg == 'accountExpired') {
				  		$("#_accountExpiredWarning").modal("show");
				  	}
				  }
				});
			}, 8000); */

			/*window.setInterval(function() {
				getMessageNotification();
			}, 1000*10); */
			
			$("#_loginSeizeWarning .btn.green").click(function() {
				$('#logOut').click();
			});
			
			$("#_accountExpiredWarning .btn.green").click(function() {
				$('#logOut').click();
			});
			
			//弹出修改密码窗口
			$('#modify_password').click(function(){
				$("#form_loginName").val(loginName);
				$("#modify_password_form").modal({show:true,keyboard:false});
			});
			
			//保存修改
			$('#save_new_pass').click(function(){
				if(!validateMyPassForm("pass_form")) {
					return false;
				}
				var newpass = $("#form_newpass").val();
				var oldpass = $("#form_oldpass").val();
				var user={};
				$.ajax({
				  type:'GET',
				  url: 'main/modifyPass.mvc',
				  dataType: "json",
				  data : {
				  	"loginName" : loginName,
				  	"newpass" : newpass,
				  	"oldpass" : oldpass
				  },
				  success:function(data){
			 		 if(data.msg==true) {
			 		 	rmsBox.notify("success", {msg: "密码修改成功！请重新登陆",width:"300px",delay:"3000"});
			 		 	window.setTimeout(function (){
			 		 		$('#logOut').click();
			 		 	}, 3000);
			 		 } else if (data.msg==false) {
			 		 	util.showModal("#_index_alert", "修改出错！");
			 		 	$("#pass_form input:not(#form_loginName)").val('');
			 		 } else if (data.msg=="wrong") {
			 		 	util.showModal("#_index_alert", "原密码错误，请重新输入！");
			 		 	$("#pass_form input:not(#form_loginName)").val('');
			 		 }
				  }
				});
			});
			//点击取消
			var formResetFlag = false;
			$("#modifypass_btn_close").click(function(){
				$("#pass_form input").val('');
				if (formResetFlag) {
					$("#pass_form").validate().resetForm();
				}
			});
			
			//表单验证
			function validateMyPassForm(formId){
				formResetFlag = true;
				return $( '#' + formId ).validate({
					errorElement: 'em',
					focusInvalid: false, 
					ignore: "",
			        rules:{  
			        	loginName: 'required',
			        	oldpass:'required',
			        	newpass:{
			        		'required' : true,
			        		'chechPassStds' : true
			        	},
			        	confirmpass: {
			        		'required':true,
			        		checkSame : true
		        		}
        			},
			        messages:{
			        	loginName: '不能为空',
			        	oldpass:'不能为空',
			        	newpass:{
			        		'required' : '不能为空',
			        		'chechPassStds' : '密码需在6~14位，以字母开头，不允许使用特殊符号'
			        	},
			        	confirmpass: {
			        		'required':'不能为空',
			        		checkSame : '两次密码输入不一致'
			        	}
			        }, 
			        errorPlacement: function (error, element) {
			        	//默认以span形式显示在输入框后
			           error.insertAfter(element);
			           $(element.next()).attr('title', $(error).text()).tooltip();
			           $(error).text('');
        			}
    			}).form();
			}
			$.validator.addMethod("checkSame",function(value,element,params){
			    var newpass = $("#form_newpass").val();
			    return value == newpass;
			},"两次输入的密码不相同");
			$.validator.addMethod("chechPassStds",function(value,element,params){
			    var checkpass = /^[a-z,A-Z][a-zA-Z0-9]{5,13}$/;
			    return this.optional(element)||(checkpass.test(value));
			},"");
		});
	</script>
</body>
</html>